
//————————————————————————————————————————————————新建产品————————————————————————————
$(".newPro").click(function(){
		layer.open({
			type: 2,
			title: ['新建产品','background-color:#6d6e72; color:#fff;font-size:14px;'],
			shadeClose: true,
			shade: [0.9,'#cfcfcf'],
			area: ['100%', '98%'],  
			content: ['../ak/newBuiltProduct.html'],// iframe的url，no代表不显示滚动条
			end:function(){
				getAjax();
			}
				
		});
})
//————————————————————————————————————————————————修改产品————————————————————————————
$("table").delegate(".edit","click",function(){
		var proId = $(this).parent().parent().find(".prdId").text();
		var flightType = $(this).parent().parent().find("span[class=returnType]").text();
		
		layer.open({
			type: 2,
			title: ['修改产品','background-color:#6d6e72; color:#fff;font-size:14px;'],
			shadeClose: true,
			shade: [0.9,'#cfcfcf'],
			area: ['100%', '98%'],  
			content: ['../ak/editProduct.html?proId='+proId+'&flightType='+flightType],// iframe的url，no代表不显示滚动条
			end:function(){
				getAjax();
			}
				
		});
})
//————————————————————————————————————————————————组合产品详情————————————————————————————
$("table").delegate(".detail","click",function(){
		var proId = $(this).parent().parent().find(".prdId").text();
		layer.open({
			type: 2,
			title: ['组合产品详情','background-color:#6d6e72; color:#fff;font-size:14px;'],
			shadeClose: true,
			shade: [0.9,'#cfcfcf'],
			area: ['98%', '98%'],  
			content: ['../ak/productDetail.html?proId='+proId],// iframe的url，no代表不显示滚动条
			end:function(){
				getAjax();
			}
				
		});
})

//————————————————————————————————————————————————运价方案————————————————————————————
$("table").delegate(".fareName1,.fareName2","click",function(){
	var fareName=$(this).attr("data");	
	layer.open({
		type: 2,
		title: ['运价方案','background-color:#6d6e72; color:#fff;font-size:14px;'],
		shadeClose: true,
		shade: [0.9,'#cfcfcf'],
		area: ['100%', '98%'],  
		content: ['../ak/pricePlan.html?fareName='+fareName],// iframe的url，no代表不显示滚动条
		end:function(){
			getAjax();
		}
			
	});
})
//————————————————————————————————————————————————选择所有————————————————————————————
	$(".checkAll").click(function(){		
			if(this.checked){
				$(".check").prop('checked','checked')				
			}else{
				$(".check").prop('checked',false)		
			}		
	})
	
//————————————————————————————————————————————————取消产品————————————————————————————
	$(".cancelProduct").click(function(){
		var checkArr = [];
		var prdIdArr = [];
		var length = $(".clear input[type=checkbox]").length
		for(var i=0;i<length;i++){
			if($(".clear input:checkbox")[i].checked){
				checkArr.push(i)						
			}
		}
		for(var i=0;i<checkArr.length;i++){
			prdIdArr.push($(".prdId").eq(checkArr[i]).text())
		}
		if(prdIdArr.length==0){
			layer.msg("请选择需要取消的产品！",{icon:2,time:1000})
			return false;
		}else{
			
			//询问框
			layer.confirm('确认取消该产品？', {
					title:['温馨提示','background-color:#6d6e72;color:#fff;font-size:14px;'],
					shade: [0.9,'#cfcfcf'],
				   	btn: ['确定','取消'] //按钮
				}, function(){
					layer.msg('取消中...', {icon: 16,shade: 0.01});
					$.ajax({
						type:"post",
						url:"../product/cancel?temp="+Math.random(),
						contentType:'application/json;charset=utf-8',
						data:JSON.stringify(prdIdArr),
						async:true,
						success:function(data){
							data = JSON.parse(data)
							if(data.status=="1001"){
								layer.msg('取消成功', {icon: 1,time:1000},function(){
									getAjax()
								});			
							}else{
								//layer.msg(data.message, {icon: 2,time:2000})
								//失败的弹出框
								layer.confirm(data.message, {
									title:['取消失败','background-color:#6d6e72;color:#fff'],
								   	btn: ['确定'] //按钮
								}, function(){
									layer.closeAll('dialog');
								});
							}
						},
						error:function(){
							
						}
					});
					
				});	
		}
	
	})
//————————————————————————————————————————————————点击查询————————————————————————————	
	$(".querySpan").click(function(){
		$(".page").val("1")
		getAjax()
	})
	
	
//————————————————————————————————————————————————渲染页面————————————————————————————
	
		var totalAmount
		var totalPage
		var nowPage
	function getAjax(){		
			var flitNo = ($(".flitNo").val()).toUpperCase();
			var productId = $(".productId").val();
			var depDate = $(".depDate").val();
			var arrDate = $(".arrDate").val();
			var pageNum = $(".page").val()-0;
			var pageSize = $(".pageSize").val()-0;
			var stat = $(".status").val();
			layer.load();
 			$.ajax({
				type:"get",
				url:"../product/query?productId="+productId+"&fltNo="+flitNo+"&depDate="+depDate+"&arrDate="+arrDate+"&pageNum="+pageNum+"&pageSize="+pageSize+"&stat="+stat+"&temp="+Math.random(),
				async:true,
				success:function(data){
					layer.closeAll('loading');
					data = JSON.parse(data)
					totalAmount = data.data.total
					if(totalAmount=="0"){
						layer.msg("没有搜索到结果")
						return false;
					}
					totalPage = data.data.pages
					nowPage = data.data.pageNum
					//共多少条
					$(".totalAmount").text(totalAmount)
					//共多少页
					$(".totalPage").text(totalPage)
					//第几页
					$(".nowPage").text(nowPage)
					//每次经行请求时清空页面原有数据
					$(".clear").empty();
					var str = "";
					var No = 0;	
					var editright=$(".searchPanle input[type=hidden]").val();
					var editrightStr="";
					/*编辑资源权限的设置begin*/
					if(editright=="1"){
						editrightStr+="<td><span title=编辑 class='edit iconfont'>&#xe681;</span></td>"
					}else{
						editrightStr+="<td></td>"
					}
					/*编辑资源权限的设置end*/
					for(var i=0;i<data.data.list.length;i++){
						if(data.data.list[i].status=="SS"){
							data.data.list[i].status="执行中"
						}if(data.data.list[i].status=="US"){
							data.data.list[i].status="已取消"
						}												
						No++
						str+="<tr>" 						
						str+="<td><span><input class='check' type='checkbox'/></span><span class='returnType' style='display:none'>"+data.data.list[i].returnType+"</span></td>" 						
						if(data.data.list[i].isFreeType){
							str+=	"<td><span class='aaaaaa'>"+No+"</span></td>" +
							"<td class=prdId><span class='detail faa000'>"+data.data.list[i].prdId+"</span><span class='freeTicketSign'>免票</span></td>" 
						}else{
							str+=	"<td><span class='aaaaaa'>"+No+"</span></td>" +
							"<td class='prdId'><span class='detail faa000'>"+data.data.list[i].prdId+"</span></td>" 
						}								
						str+=	"<td height="+legsDraw(data.data.list[i].legs).height+" class='f00aa99'>"+legsDraw(data.data.list[i].legs).legs+"</td>" +
								"<td height="+legsDraw(data.data.list[i].legs).height+" class='f00aa99'>"+legsDraw(data.data.list[i].time).legs+"</td>" +
								"<td class='f262929'>"+data.data.list[i].availableDate+"/"+data.data.list[i].unavailableDate+"</td>" +							
								"<td height="+fareName(data.data.list[i].fareName,data.data.list[i].freeFareId).height+"><span class='fareName faa000'>"+fareName(data.data.list[i].fareName,data.data.list[i].freeFareId).fare+"</span></td>" +	
								"<td class='statuspro'>"+data.data.list[i].status+"</td>" +
								editrightStr+
							//	"<td><span title=编辑 class='edit iconfont'>&#xe681;</span></td>" +
							 "</tr>"
					}
					$(".clear").append(str)
					/*控制不同的状态，字体颜色不同begin*/
					for(var i=0;i<$(".clear>tr").length;i++){
						if($(".statuspro").eq(i).text()=="执行中"){
							$(".statuspro").eq(i).addClass("fa2828");
						}else{
							$(".statuspro").eq(i).addClass("aaaaaa");
						}
					}
					/*控制不同的状态，字体颜色不同end*/
				}			
			});	
	}
//________________________________________多航节处理____________________________________________
	function legsDraw(legs){
		if(legs){
			var legs = legs.split("/");
			if(legs.length==1){				
				return {
					legs:legs[0],
					height:"commom"
				};
			}else if(legs.length==2){
				return {
					legs:legs[0]+"</br>"+legs[1],
					height:"higher"
				};
			}else if(legs.length==4){
				return {
					legs:legs[0]+"/"+legs[1]+"</br>"+legs[2]+"/"+legs[3],
					height:"higher"
				};
			}
		}			
	}
//——————————————————————————————————————————————————————————————————————————————多运价处理
	function fareName(fareName1,fareName2){		
		if(fareName1&&fareName2){
			return {
				fare:"<div class='fareName1' data="+fareName1+">"+fareName1+"</div><div class='fareName2' data="+fareName2+">"+fareName2+"<span class='freeTicketSign'>免票</span></div>",
				height:"higher"
			}
		}else if(fareName1){
			return {
				fare:"<div class='fareName1' data="+fareName1+">"+fareName1+"</div>",
				height:"commom"
			}
		}else if(fareName2){
			return {
				fare:"<div class='fareName2' data="+fareName2+">"+fareName2+"<span class='freeTicketSign'>免票</span></div>",
				height:"commom"
			}
		}else{
			return {
				fare:"",
				height:"commom"
			}
		}
	}
//________________________________________表头固定____________________________________________
	$("#dataTable").freezeHeader();
//________________________________________分页__________________________________
	$(".Pagination").load("Pagination.html",function(){
		getAjax();
	})	
